package com.edouardbataille.open.requester
{
	import com.edouardbataille.open.MySqlSocket;
	import com.edouardbataille.open.MysqlConst;
	import com.edouardbataille.open.handler.QueryResultHandler;
	import com.edouardbataille.open.sender.Sender;
	
	import flash.utils.ByteArray;
	
	import mx.rpc.AsyncToken;
	
	public class Query extends Sender
	{
		private var _query : String;
		
		public function Query(con : MySqlSocket)
		{
			super (con);
			handler = new QueryResultHandler();
		}

		public function execute (query : String) : AsyncToken
		{
			super.queryStr = query;
			token = new AsyncToken ();
			_query = query;
			var response : ByteArray = new ByteArray ();
			
			response.writeByte(MysqlConst.COM_QUERY);
			response.writeMultiByte(query, "latin1");
			
			send(response);
			return token;
		}
	}
}